package org.budo.canal.zookeeper;

import org.springframework.beans.factory.FactoryBean;

import com.alibaba.otter.canal.common.zookeeper.ZkClientx;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * 没有 url 就返回 ZkClientx 类型的 null
 * @author limingwei
 */
@Getter
@Setter
@Slf4j
public class ZkClientxFactoryBean implements FactoryBean<ZkClientx> {
    private String url;

    @Override
    public ZkClientx getObject() throws Exception {
        String url = this.getUrl();
        if (null == url || url.isEmpty() || url.startsWith("${")) {
            log.error("#24 url=" + url + ", return null");
            return null;
        }

        return ZkClientx.getZkClient(url);
    }

    @Override
    public Class<?> getObjectType() {
        return ZkClientx.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}